package com.hjtech.baselib.utils

import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import java.util.concurrent.TimeUnit


/*
 * 项目名:    Pigeon
 * 包名       cn.hjtech.pigeon.common.utils
 * 文件名:    RxCountDown
 * 创建者:    ZJB
 * 创建时间:  2017/5/3 on 10:11
 * 描述:     TODO 倒计时
 */
object RxCountDown {
    fun countdown(time: Int): Observable<Int> {
        var time = time
        if (time < 0) time = 0
        val countTime = time
        return Observable.interval(0, 1, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .map { t -> countTime - t!!.toInt() }
                .take((countTime + 1).toLong())

    }
}
